var app = getApp()
var getUser = that =>{
  let token = wx.getStorageSync('token')
  let userId = wx.getStorageSync('userId')
  let params = {
    token: token
  }
  wx.request({
    url: 'https://qili.docdic.com/api/user/' + userId + '?token=' + token,
    method: 'get',
    data: params,
    success:function(res){
     let data =res.data.data
     wx.setStorageSync('has_stall', data.status.has_stall)
     wx.setStorageSync('has_factory', data.status.has_factory)
     app.globalData.stallInfo = data.stall
     app.globalData.factoryInfo = data.factory
     app.globalData.tel = data.cellphone


     that.setData(data)
    }
  })
}

Page({

  /**
   * 页面的初始数据
   */
  data: {
    
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    wx.getUserInfo({
      success: function (res) {
        console.log(res)
        var userInfo = res.userInfo
        var nickName = userInfo.nickName
        var avatarUrl = userInfo.avatarUrl
        var gender = userInfo.gender //性别 0：未知、1：男、2：女
        var province = userInfo.province
        var city = userInfo.city
        var country = userInfo.country
        that.setData({
          userImg: avatarUrl,
          nickName: nickName
        })
      }
    })
    getUser(this)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  },
  myFactory: function () {
    wx.navigateTo({
      url: './myfactory/myfactory',
    })
  },
  myStall: function () {
    wx.navigateTo({
      url: './mystall/mystall',
    })
  },
  creatinfo: function (){
    wx.navigateTo({
      url: './creatinfo/creatinfo',
    })
  },
  myorder:function(){
    wx.navigateTo({
      url: './myorder/myorder',
    })
  }
})